;;windowm.el -*- mode: emacs-lisp -*-
(defun buffer-window (buffer-or-name)
  "This function can be thought of as the inverse of window-buffer. However, there is
no guarantee that a buffer will be displayed in a window. If the buffer is present in a 
window, returns that window. Otherwise, returns nil."
  (let ((matching-window nil))
    (walk-window-tree (lambda (window)
			(let ((bufname (if (bufferp buffer-or-name)
					   (buffer-name buffer-or-name)
					 (if (stringp buffer-or-name)
					     buffer-or-name))))
			  (and (string-match bufname (buffer-name (window-buffer window)))
			       (setq matching-window window)))))
    matching-window))
(defun current-window ()
  (selected-window))
(defun switch-to-window-with-buffer ()
  (interactive)
  (let ((bufname (read-string "Buffer Name : " nil nil (buffer-name (window-buffer (next-window))))))
    (select-window (buffer-window bufname))))
